//
//  WmcAlertSettingPhotoNumItemView.swift
//  YPWatermarkCamera
//
//  Created by Json on 2023/8/1.
//

import UIKit
import RxRelay

class WmcAlertSettingPhotoNumItemView: WmcBaseView {

    private lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.font = 15.wmc_scaleFont(weight: .medium)
        label.textColor = UIColor.wmc_blackH1_000000
        return label
    }()
    
    private lazy var stackView: UIStackView = {
        let stackV = UIStackView()
        stackV.axis = .horizontal
        stackV.spacing = 0.0
        stackV.distribution = .fill
        stackV.alignment = .center
        return stackV
    }()
    
    private lazy var addButton: UIButton = {
        let button = UIButton()
        button.setImage("icon_add_28".wmc_image, for: .normal)
        return button
    }()
    
    private lazy var minusButton: UIButton = {
        let button = UIButton()
        button.setImage("icon_minus_28".wmc_image, for: .normal)
        return button
    }()
    
    private lazy var numberLabel: UILabel = {
        let label = UILabel()
        label.font = 17.wmc_scaleFont(weight: .medium)
        label.textColor = UIColor.wmc_blackH1_000000
        label.textAlignment = .center
        return label
    }()
    
    var number: Int = 0 {
        didSet {
            numberLabel.text = "\(number)"
            titleLabel.text = "拍摄完 \(number) 张自动完成拼图"
        }
    }
    
    /// 点击加号回调
    let addAction: PublishRelay<Void> = .init()
    /// 点击减号回调
    let minusAction: PublishRelay<Void> = .init()

    // MARK: UI
    override func makeUI() {
        super.makeUI()
        let hMargin = 12.0.wmc_autoHor
        let buttonWH = 28.0.wmc_autoHor
        
        backgroundColor = UIColor.wmc_grayH18_F0F0F0
        layer.cornerRadius = 8.0
        clipsToBounds = true
        
        // stackView
        addSubview(stackView)
        stackView.snp.makeConstraints { make in
            make.right.equalTo(-hMargin)
            make.top.bottom.equalToSuperview()
        }
        // 减号
        stackView.addArrangedSubview(minusButton)
        minusButton.snp.makeConstraints { make in
            make.width.height.equalTo(buttonWH)
        }
        // 数字
        stackView.addArrangedSubview(numberLabel)
        numberLabel.snp.makeConstraints { make in
            make.width.equalTo(38.0.wmc_autoHor)
        }
        // 加号
        stackView.addArrangedSubview(addButton)
        addButton.snp.makeConstraints { make in
            make.width.height.equalTo(buttonWH)
        }
        // 标题
        addSubview(titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.left.equalTo(hMargin)
            make.centerY.equalToSuperview()
            make.right.equalTo(stackView.snp.left).offset(-hMargin)
        }
        // 默认是2
        self.number = 2
    }
    
    // MARK: Bind Action
    override func bindViewAction() {
        super.bindViewAction()
        addButton.rx.tap.bind(to: addAction).disposed(by: rx.disposeBag)
        minusButton.rx.tap.bind(to: minusAction).disposed(by: rx.disposeBag)
    }
}
